/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package logic;


/**
 *
 * @author kotionokyurievna
 */
import java.util.Calendar;
import java.util.Date;

public class MetroCardDateLimit extends MetroCard{
    private Date expirationDate;
    private CardDaysLimit limit;
    
    public MetroCardDateLimit( CardDataBase cardDataBase, CardDaysLimit limit, CardType cardType){
        setPassChecker( new DatePassChecker ( this, cardDataBase) );
        setExpirationDate(limit);
        setType(cardType);
    }
    
    public Date getExpirationDate(){
        return expirationDate;
    }
    
    public final void setExpirationDate( CardDaysLimit limit){
        Calendar calendar = Calendar.getInstance();
          
        if ( limit.getLimit() > 0){
            this.limit = limit;
            calendar.add(calendar.DATE, limit.getLimit());
            expirationDate = calendar.getTime();
            calendar.add(calendar.DATE, -limit.getLimit());
        }
        
    }
    
    public CardDaysLimit getLimit(){
        return this.limit;
    }
}
